2023-11-13
0 만들기
https://www.acmicpc.net/problem/7490
문자열 숫자 사이에 연산을 집어넣었을 때 0이 되는 모든 수식을 출력하는 문제
import copy def recursive(array, n): if len(array) == n: operators_list.append(copy.deepcopy(array)) return array.append(' ') recursive(array, n) array.pop() array.append('+') recursive(array, n) array.pop() array.append('-') recursive(array, n) array.pop() test_case = int(input()) for _ in range(test_case): operators_list = [] n = int(input()) recursive([], n - 1) integers = [i for i in range(1, n + 1)] for operators in operators_list: string = "" for i in range(n - 1): string += str(integers[i]) + operators[i] string += str(integers[-1]) if eval(string.replace(" ", "")) == 0: print(string) print()
